let mysql = require('mysql');
// 创建连接
const connection = mysql.createConnection({
    host:'localhost',
    port:3306,
    user:'root',
    password:'root',
    database:'cms'
});
connection.connect();
/* connection.query('SELECT  * FROM account',(err,result,fields)=>{
    console.log(result);
}); */
connection.beginTransaction(function(){
    connection.query('UPDATE account SET amount = amount -50 WHERE id = 1',function(err,result,fields){
        if(err){
            return connection.rollback();
        }
        connection.query('UPDATE account SET amount = amount +50 WHERE id = 2',function(err,result,fields){
            if(err){
                return connection.rollback();
            }
            connection.commit();
        });
    });
});